const domainName = getApp().globalData.domainName
const header = {'content-type':'application/x-www-form-urlencoded'}
const user_id = wx.getStorageSync('user_id')

// pages/login/login.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    logo_green_bg:'https://yqwl.top/app_images/logo_green_bg.jpg',
  },

    // 更新头像选项,// 上传微信头像
    onChooseAvatar(e){
      let avatarUrl = e.detail.avatarUrl
        wx.uploadFile({
          filePath: avatarUrl,
          name: 'files',
          url: domainName + '/update_avatar',
          formData: {
            user_id,
          },
          header: header,
          timeout: 0,
          success: res => {
            let data = JSON.parse(res.data)
            if(data.update_res){
              this.setData({
                avatar:avatarUrl
              })
              wx.showToast({
                title: '更新完成',
                duration: 1500,
                icon: 'success',
                mask: false,
              })
            }else{
              wx.showToast({
                title: '稍后重试',
                duration: 1500,
                icon: 'error',
                mask: false,
              })
            }
          },
        })
    },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      avatar:options.avatar
    })
  },

})